<?php

namespace App\Http\Resources\Mini\NoticeResource;

use Illuminate\Http\Resources\Json\ResourceCollection;

class NoticeClassCollection extends ResourceCollection
{
    /**
     * Transform the resource collection into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
//        return parent::toArray($request);
        return [
            'data' => $this->collection->map(function ($item) {
                return [
                    'name'        => $item->name,//公告标题
                    'content'     => $item->content,//公告内容
                    "author"      => $item->one_estate->username,//公告发布者
                    "avatar"      => $item->one_estate->avatar,//公告发布者
                    'start_time'  => $item->start_time,//
                    'end_time'    => $item->end_time,
                    'create_time' => $item->create_time,
                    'status'      => $item->status
                ];
            }),
            'total'        => $this->total(), // 数据总数
            'per_page'     => $this->perPage(), // 每页数量
            'current_page' => $this->currentPage(), // 当前页码
        ];
    }
}
